function checkAndUpdate(el, binding, vnode) {
  const { value } = binding
  const store = vnode.context.$store

  const hasPermission = permission => {
    if (!store.getters['userStore/havePermission']) {
      console.error('userStore havePermission error')
      return false
    }
    return store.getters['userStore/havePermission'](permission)
  }
  if (value) {
    const hasAuth = hasPermission(value)
    if (!hasAuth && el.parentNode) el.parentNode.removeChild(el)
  }
}
export default {
  inserted(el, binding, vnode) {
    checkAndUpdate(el, binding, vnode)
  },
  updated(el, binding, vnode) {
    // 只有值变化时才重新检查
    if (binding.value !== binding.oldValue) {
      checkAndUpdate(el, binding, vnode)
    }
  }
}
